package  
{
	import code.Random;
	import flash.display.Sprite;
	import flash.sampler.getMasterString;
	import flash.system.System;
	import flash.text.TextField;
	import flash.utils.describeType;
	import flash.utils.Dictionary;
	import xxl.ioc.Injector;
	import xxl.robotlegs.base.Context;
	import xxl.signals.base.Slot;
	
	/**
	 * ...
	 * @author XXL
	 */
	public class Main3 extends Sprite 
	{
		private var ioc:Injector = new Injector();
		
		[Inject(name = "a1")]
		public var abc:Sprite;
		
		public function Main3() 
		{
			ioc.map(Sprite).toValue(this);
			//ioc.map(Test);
			//var t1:* = ioc.getInstance(Test);
			//ioc.injectInto(new Test(new Sprite));
			ioc.map(Test).asSingleton();
			ioc.map(Test, "b1").asSingleton();
			trace(ioc.getInstance(Test) === ioc.getInstance(Test, "b1"));
			ioc.destroyInstance(ioc.getInstance(Test));
			trace("----");
			ioc.teardown();
			//ioc.map(Sprite, "a1").toValue(this);
			//ioc.injectInto(this);
			//trace(this === ioc.getInstance(Sprite, "a1"));
			
			//
			//var xml:XML = describeType(Slot);
			//
			//var r:Random = new Random(123456);
			//for (var i:int = 0; i < 100; i++) 
			//{
				//trace(r.nextNumber());
			//}
			
			//var factoryNode:XML = xml.factory[0];
			//var node:XML = factoryNode.constructor[0];
			//trace(xml);
			//trace(node);
			//trace("------------");
			//trace(factoryNode.parent());
			
			//var args:XMLList = node.parent().metadata.arg;
			//var parametersMap:Dictionary = new Dictionary();
			//var len:int = args.length();
			//for (var i:int = 0; i < len; i++) 
			//{
				//var parameter:XML = args[i];
				//var key:String = parameter.@key;
				//parametersMap[key] = parametersMap[key] ? parametersMap[key] + "," + parameter.attribute("value") : parameter.attribute("value");
			//}
			//trace(parametersMap);
			//trace(node.parameter);
			
			//fun1();
		}
		
		/**
		 * 这种情况下会出现xml被持有
		 */
		private function fun1():void
		{
			var xml:XML = describeType(Slot);
			var xml2:XML = new XML(xml.toString());
			var str:String = xml2.factory[0].@type;
			System.disposeXML(xml);
			System.disposeXML(xml2);
			trace(getMasterString(str));
		}
		
	}

}